package com.zq.learing.base.实用;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @Author: zhaoqi
 * @Date: 2020/4/23 23:50
 * @Version 1.0
 */

public class WorldCount {
    public static void main(String[] args) {
        try(FileReader fileReader = new FileReader("banner.txt")) {
            int counter = 0;
            boolean state = false;
            int currentChar;
            while ((currentChar =fileReader.read()) != -1){
                if (currentChar == ' '  ||  currentChar=='\n'  || currentChar == '\t' || currentChar == '\r' ){
                    state = false;
                } else if (!state){
                    state = true;
                    counter++;
                }
            }
            System.out.println(counter);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
